package github.kawaiior.yuanchuxiuzhen.common.gongfa.base;

import github.kawaiior.yuanchuxiuzhen.common.capability.entity.ManaPower;
import github.kawaiior.yuanchuxiuzhen.common.gongfa.GongFaBase;
import github.kawaiior.yuanchuxiuzhen.core.init.GongFaInit;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.world.World;

public class QingShanZhenDiGong extends GongFaBase {
    public QingShanZhenDiGong(String itemName) {
        super(ManaPower.ManaRoot.EARTH, 10000, GongFaInit.YAN_TU_JUE, itemName);
    }


    @Override
    public void onPlayerLearn(PlayerEntity player, World world, ManaPower power) {

    }

    @Override
    public void onPlayerLearnFinish(PlayerEntity player, World world, ManaPower power) {
        // TODO: 添加效果
    }

    public static void onPlayerDestroyBlock(PlayerEntity player, World world, Block block, ManaPower power){
        learn(player, world, block, power);
    }

    private static void learn(PlayerEntity player, World world, Block block, ManaPower power){
        if (!power.isLearningGongFa(GongFaInit.QING_SHAN_ZHEN_DI_GONG)){
            return;
        }

        power.addGongFaExp(player, world, 1);
    }

    // 效果
    public static void onPlayerTick(PlayerEntity player, ManaPower power){
        if (!power.isLearnedGongFa(GongFaInit.QING_SHAN_ZHEN_DI_GONG)){
            return;
        }

        if (player.isPotionActive(Effects.RESISTANCE)){
            return;
        }

        player.addPotionEffect(new EffectInstance(Effects.RESISTANCE, 200000, 2));
    }

}
